package com.example.monitor.model.enums;

public enum Gender {
    MALE("male", "男"),
    FEMALE("female", "女");

    private final String code;
    private final String description;

    Gender(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static Gender fromCode(String code) {
        for (Gender gender : Gender.values()) {
            if (gender.getCode().equals(code)) {
                return gender;
            }
        }
        throw new IllegalArgumentException("Invalid gender code: " + code);
    }
    // 添加更灵活的fromString方法
    public static Gender fromString(String value) {
        if (value == null) return null;
        for (Gender gender : Gender.values()) {
            if (gender.code.equalsIgnoreCase(value) ||
                    gender.name().equalsIgnoreCase(value)) {
                return gender;
            }
        }
        throw new IllegalArgumentException("Invalid gender value: " + value);
    }

}
